<template>
    <div>
        <el-dialog
            :title="!form.id ? '新增' : '修改'"
            :visible.sync="visible"
            :close-on-click-modal="false">

            <div class="table_form_wrap">
                <el-form ref="form" :model="form" :rules="rules" @keyup.enter.native="handleSubmit()" label-width="120px">
                    <el-form-item label="订单ID" prop="orderId">
                        <el-input placeholder="" v-model="form.orderId" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="订单类型：0->实物订单，2->非实物订单（非实物订单不享受任何折扣），3->活动订单" prop="orderType">
                        <el-input placeholder="" v-model="form.orderType" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="退货商品ID" prop="skuId">
                        <el-input placeholder="" v-model="form.skuId" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="会员名称" prop="memberUsername">
                        <el-input placeholder="" v-model="form.memberUsername" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="退款金额" prop="returnAmount">
                        <el-input placeholder="" v-model="form.returnAmount" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="退货人姓名" prop="returnName">
                        <el-input placeholder="" v-model="form.returnName" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="退货人电话" prop="returnPhone">
                        <el-input placeholder="" v-model="form.returnPhone" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="申请状态[0->待处理；1->退货中；2->已完成；3->已拒绝]" prop="status">
                        <el-input placeholder="" v-model="form.status" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="处理时间" prop="handleTime">
                        <el-input placeholder="" v-model="form.handleTime" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="商品图片" prop="skuImg">
                        <el-input placeholder="" v-model="form.skuImg" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="商品名称" prop="skuName">
                        <el-input placeholder="" v-model="form.skuName" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="商品品牌" prop="skuBrand">
                        <el-input placeholder="" v-model="form.skuBrand" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="商品销售属性(JSON)" prop="skuAttrsVals">
                        <el-input placeholder="" v-model="form.skuAttrsVals" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="退货数量" prop="skuCount">
                        <el-input placeholder="" v-model="form.skuCount" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="商品单价" prop="skuPrice">
                        <el-input placeholder="" v-model="form.skuPrice" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="商品实际支付单价" prop="skuRealPrice">
                        <el-input placeholder="" v-model="form.skuRealPrice" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="原因" prop="reason">
                        <el-input placeholder="" v-model="form.reason" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="描述" prop="description">
                        <el-input placeholder="" v-model="form.description" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="凭证图片，以逗号隔开" prop="descPics">
                        <el-input placeholder="" v-model="form.descPics" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="处理备注" prop="handleNote">
                        <el-input placeholder="" v-model="form.handleNote" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="处理人员" prop="handleMan">
                        <el-input placeholder="" v-model="form.handleMan" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="收货人" prop="receiveMan">
                        <el-input placeholder="" v-model="form.receiveMan" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="收货时间" prop="receiveTime">
                        <el-input placeholder="" v-model="form.receiveTime" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="收货备注" prop="receiveNote">
                        <el-input placeholder="" v-model="form.receiveNote" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="收货电话" prop="receivePhone">
                        <el-input placeholder="" v-model="form.receivePhone" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="公司收货地址" prop="companyAddress">
                        <el-input placeholder="" v-model="form.companyAddress" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <el-form-item label="申请时间" prop="ctime">
                        <el-input placeholder="" v-model="form.ctime" clearable style="width: 80%"></el-input>
                    </el-form-item>
                    <!--
                    <el-form-item label="状态" prop="status">
                        <el-radio-group v-model="form.status">
                            <el-radio-button :label="1">正常</el-radio-button>
                            <el-radio-button :label="0">锁定</el-radio-button>
                        </el-radio-group>
                    </el-form-item>
                    <el-form-item label="薪资" prop="salary">
                        <el-input-number v-model="form.salary" :precision="2" :step="0.01" :min="0.00" style="width: 80%;"></el-input-number>
                    </el-form-item>
                    <el-form-item label="排序" prop="sort">
                        <el-input-number v-model="form.sort" :min="1" :max="10000" placeholder="排序"></el-input-number>
                    </el-form-item>
                    <el-form-item label="性别" prop="sex">
                        <el-select v-model="form.sex" placeholder="请选择">
                            <el-option label="男" value="男"></el-option>
                            <el-option label="女" value="女"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="生日" prop="birthday">
                        <el-date-picker
                            v-model="form.birthday"
                            type="date"
                            placeholder="选择日期"
                            value-format="yyyy-MM-dd"
                            style="width: 63%;">
                        </el-date-picker>
                    </el-form-item>
                    <el-form-item label="备注" prop="remarks">
                        <el-input v-model="form.remarks" type="textarea" :rows="4" placeholder="请输入内容" style="width: 80%;"></el-input>
                    </el-form-item>
                    -->

                </el-form>
            </div>


            <div slot="footer" class="dialog-footer">
                <el-button @click="visible = false">取 消</el-button>
                <el-button @click="handleSubmit()" type="primary" :submitLoading="submitLoading">提 交</el-button>
            </div>

        </el-dialog>
    </div>
</template>

<script>
export default {
    data() {
        return {
            visible: false,
            submitLoading: false,

            form: {
                orderId: null,
                orderType: null,
                skuId: null,
                memberUsername: null,
                returnAmount: null,
                returnName: null,
                returnPhone: null,
                status: null,
                handleTime: null,
                skuImg: null,
                skuName: null,
                skuBrand: null,
                skuAttrsVals: null,
                skuCount: null,
                skuPrice: null,
                skuRealPrice: null,
                reason: null,
                description: null,
                descPics: null,
                handleNote: null,
                handleMan: null,
                receiveMan: null,
                receiveTime: null,
                receiveNote: null,
                receivePhone: null,
                companyAddress: null,
                ctime: null
            },
            rules: {
                orderId: [
                    { required: true, message: '订单ID不能为空', trigger: 'blur' }
                ],
                orderType: [
                    { required: true, message: '订单类型：0->实物订单，2->非实物订单（非实物订单不享受任何折扣），3->活动订单不能为空', trigger: 'blur' }
                ],
                skuId: [
                    { required: true, message: '退货商品ID不能为空', trigger: 'blur' }
                ],
                memberUsername: [
                    { required: true, message: '会员名称不能为空', trigger: 'blur' }
                ],
                returnAmount: [
                    { required: true, message: '退款金额不能为空', trigger: 'blur' }
                ],
                returnName: [
                    { required: true, message: '退货人姓名不能为空', trigger: 'blur' }
                ],
                returnPhone: [
                    { required: true, message: '退货人电话不能为空', trigger: 'blur' }
                ],
                status: [
                    { required: true, message: '申请状态[0->待处理；1->退货中；2->已完成；3->已拒绝]不能为空', trigger: 'blur' }
                ],
                handleTime: [
                    { required: true, message: '处理时间不能为空', trigger: 'blur' }
                ],
                skuImg: [
                    { required: true, message: '商品图片不能为空', trigger: 'blur' }
                ],
                skuName: [
                    { required: true, message: '商品名称不能为空', trigger: 'blur' }
                ],
                skuBrand: [
                    { required: true, message: '商品品牌不能为空', trigger: 'blur' }
                ],
                skuAttrsVals: [
                    { required: true, message: '商品销售属性(JSON)不能为空', trigger: 'blur' }
                ],
                skuCount: [
                    { required: true, message: '退货数量不能为空', trigger: 'blur' }
                ],
                skuPrice: [
                    { required: true, message: '商品单价不能为空', trigger: 'blur' }
                ],
                skuRealPrice: [
                    { required: true, message: '商品实际支付单价不能为空', trigger: 'blur' }
                ],
                reason: [
                    { required: true, message: '原因不能为空', trigger: 'blur' }
                ],
                description: [
                    { required: true, message: '描述不能为空', trigger: 'blur' }
                ],
                descPics: [
                    { required: true, message: '凭证图片，以逗号隔开不能为空', trigger: 'blur' }
                ],
                handleNote: [
                    { required: true, message: '处理备注不能为空', trigger: 'blur' }
                ],
                handleMan: [
                    { required: true, message: '处理人员不能为空', trigger: 'blur' }
                ],
                receiveMan: [
                    { required: true, message: '收货人不能为空', trigger: 'blur' }
                ],
                receiveTime: [
                    { required: true, message: '收货时间不能为空', trigger: 'blur' }
                ],
                receiveNote: [
                    { required: true, message: '收货备注不能为空', trigger: 'blur' }
                ],
                receivePhone: [
                    { required: true, message: '收货电话不能为空', trigger: 'blur' }
                ],
                companyAddress: [
                    { required: true, message: '公司收货地址不能为空', trigger: 'blur' }
                ],
                ctime: [
                    { required: true, message: '申请时间不能为空', trigger: 'blur' }
                ],
            }
        }
    },

    methods: {
        init(id) {
            const refs = this.$refs
            // 情况表单数据
            this.form.id = id || null
            this.visible = true

            this.$nextTick(() => {
                refs['form'].resetFields()
                if(this.form.id) {
                    this.getInfo(this.form.id)
                }
            })
        },

        /**
         * 详细信息
         */
        async getInfo(id) {
            if (id) {
                const res = await this.$http({
                    url: '/mall/omsorderreturnapply/info/' + id,
                    method: 'GET'
                })
                this.form = Object.assign({}, res.data)
            }
        },

        /**
         * 提交表单
         */
        async handleSubmit() {
            const refs = this.$refs
            this.submitLoading = true
            const valid = await refs['form'].validate().catch(() => {})
            if(valid) {
                const res = await this.$http({
                    url: `/mall/omsorderreturnapply/${!this.form.id ? 'save' : 'update'}`,
                    method: 'POST',
                    data: this.form
                })
                if (this.ResultMessage(res)) {
                    this.$emit('refreshDataList')
                    this.submitLoading = false
                    this.visible = false
                } else {
                    this.submitLoading = false
                }
            } else {
                this.submitLoading = false
            }
        }

    }
};
</script>

<style lang="scss" scoped></style>
